import "reflect-metadata";
import { DataSource } from "typeorm"
import { User, UserAuth } from "./entity"

export const AppDataSource = new DataSource({
    type: "mysql",
    host: "localhost",
    port: 3306,
    username: "root",
    password: "liu12345",
    database: "ai_set",
    entities: [User, UserAuth],
    // entities: [__dirname + "/entity/*.ts"],
    synchronize: false,
    logging: false,
})


export async function getAppDataSource() {
  if (AppDataSource && AppDataSource.isInitialized) {
    return AppDataSource
  } else {
    await AppDataSource.initialize()
    return AppDataSource
  }
}


// to initialize the initial connection with the database, register all entities
// and "synchronize" database schema, call "initialize()" method of a newly created database
// once in your application bootstrap